package srjava.messages;

import java.io.IOException;
import java.io.StringReader;

public class ServerInfo implements Serializable {
	Address address;
    SrString name;
	ServerStatus serverStatus = ServerStatus.SS_UNKNOWN;

	public ServerInfo() {
		address = new Address();
		name = new SrString();
		serverStatus = ServerStatus.SS_UNKNOWN;
	}

	public ServerInfo(Address address, SrString name) {
		super();
		this.address = address;
		this.name = name;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public SrString getName() {
		return name;
	}

	public void setName(SrString name) {
		this.name = name;
	}

	public ServerStatus getServerStatus() {
		return serverStatus;
	}

	public void setServerStatus(ServerStatus serverStatus) {
		this.serverStatus = serverStatus;
	}

	@Override
	public String serialize() {
		String pom;
		pom = address.serialize() + name.serialize() + serverStatus.ordinal() + " ";
		return pom;
	}

	@Override
	public void deSerialize(StringReader s) throws IOException {
		address.deSerialize(s);
		name.deSerialize(s);
		serverStatus = ServerStatus.values()[IntString.parseInt(s)];
	}
	
	public static void main(String [ ] args)
	{
		ServerInfo in = new ServerInfo(new Address(new SrString("sdas"), 19), new SrString("moja ty jaskolko"));
		System.out.println(in.serialize());
		try {
			in.deSerialize(new StringReader("5 sdaas 9 15 moja t jaskolko 2 "));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(in.serialize());
	}

}
